package com.shoplook2025.brand.api.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shoplook2025.brand.api.dao.BrandMapper;
import com.shoplook2025.brand.model.Brand;
import com.shoplook2025.brand.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Service;

/**
 * @author yan
 * @date 2025/8/25
 */
@CacheConfig(cacheNames = "brand-api")
@Service
public class BrandServiceImpl implements BrandService {
    private BrandMapper brandMapper;
    @Autowired
    public void setBrandMapper(BrandMapper brandMapper) {
        this.brandMapper = brandMapper;
    }

    @Override
    public Page<Brand> findAll(com.baomidou.mybatisplus.extension.plugins.pagination.Page<Brand> page, Brand brand) {
        return brandMapper.findAll(page,brand);
    }

    @Cacheable(key = "'id:'+#id")
    @Override
    public Brand findById(Integer id) {
        return brandMapper.selectById(id);
    }

    @Override
    public int save(Brand brand) {
        return brandMapper.insert(brand);
    }

    @Override
    public boolean update(Brand brand) {
        return brandMapper.updateById(brand)>0;
    }

    @Override
    public int deleteById(Integer id) {
        return 0;
    }
}
